<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/WEB-INF/template/globalTemplate.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:t="http://myfaces.apache.org/tomahawk"
                xmlns:opif="http://www.opif.com/formathlon/jsf/tags">

    <ui:define name="title">#{msg['application.titre.gestion.session']}</ui:define>

    <ui:define name="ariane">
        <h:commandLink action="/faces/index.xhtml"  
                       value="#{msg['application.titre.accueil']}"/>
        >
        #{msg['application.titre.gestion.session']}
    </ui:define>

    <ui:define name="content">
        <h:panelGroup styleClass="titre">Liste des sessions</h:panelGroup>
        <c:forEach items="#{gestSessionBean.formationFacade.formationEnCours}" var="formation">
            <h:panelGroup styleClass="sousTitre">
                <h:outputText value="Formation : #{formation.libelle}"/>
            </h:panelGroup>
            <p:commandLink styleClass="lienAction lienCreer"
                           value="#{msg['application.creer']} une session"
                           action="#{gestSessionBean.ajouter(formation)}"
                           update="popup"  />
            
            <p:dataTable id="dataTableListeSession" var="sessionForm" value="#{gestSessionBean.listSessionEnCours(formation)}" 
                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                         rowsPerPageTemplate="5,10,15" rowIndexVar="numero" emptyMessage="#{msg['application.emptyMessage']}">
                <p:column headerText="Session">
                    <h:outputText value="#{numero+1}" />
                </p:column>
                <p:column headerText="Date">
                    Du&nbsp;
                    <h:outputText value="#{sessionForm.dateDebut}">
                        <f:convertDateTime pattern="dd/MM/yyyy"/>
                    </h:outputText>
                    &nbsp;au&nbsp;
                    <h:outputText value="#{sessionForm.dateFin}">
                        <f:convertDateTime pattern="dd/MM/yyyy"/>
                    </h:outputText>
                </p:column>
                <p:column headerText="Instructeur">
                    <h:outputText value="#{sessionForm.instructeur}" />
                </p:column>
                <p:column headerText="Inscrit">
                    <h:panelGroup style="cursor:default">
                        <h:outputText value=" #{sessionForm.nbPlaceMini} "
                                      id="outputMini"/>
                        <p:tooltip for="outputMini"
                                   value="Minimum d'inscriptions autorisées"
                                   showEffect="slide"
                                   hideEffect="fade"/>
                        /
                        <h:outputText value=" #{gestSessionBean.nbInscrit(sessionForm)} "
                                      id="outputNb"
                                      style="font-weight:bold"/>
                        <p:tooltip for="outputNb"
                                   value="Inscriptions validées"
                                   showEffect="slide"
                                   hideEffect="fade"/>
                        /
                        <h:outputText value=" #{sessionForm.nbPlaceMax} "
                                      id="outputMaxi"/>
                        <p:tooltip for="outputMaxi"
                                   value="Maximum d'inscriptions autorisées"
                                   showEffect="slide"
                                   hideEffect="fade"/>
                    </h:panelGroup>
                </p:column>
                <p:column headerText="Etat" >
                    <h:outputText value="#{sessionForm.etat.libelle}" />
                </p:column>
                <p:column headerText="Action(s)">
                    <p:commandLink action="#{gestSessionBean.modifier(sessionForm)}"
                                   value="Modifier"  
                                   update="globalForm:popup"
                                   rendered="#{gestSessionBean.isModifiable(sessionForm)}"/>
                    <h:outputText value=" " rendered="#{gestSessionBean.isModifiable(sessionForm)}"/>
                    <p:commandLink action="#{gestSessionBean.supprimer(sessionForm)}"
                                   value="Supprimer"  
                                   update="globalForm:confirm"
                                   rendered="#{gestSessionBean.isSupprimable(sessionForm)}"/>
                    <h:outputText value=" " rendered="#{gestSessionBean.isSupprimable(sessionForm)}"/>
                    <p:commandLink action="#{gestSessionBean.ouvrir(sessionForm)}"
                                   value="Ouvrir"  
                                   update="globalForm"
                                   rendered="#{gestSessionBean.isModifiable(sessionForm)}"/>
                    <h:outputText value=" " rendered="#{gestSessionBean.isModifiable(sessionForm)}"/>
                    <p:commandLink action="#{gestSessionBean.cloturer(sessionForm)}"
                                   value="Clôturer"  
                                   update="globalForm"
                                   rendered="#{gestSessionBean.isOuverte(sessionForm)}"/>
                </p:column>
            </p:dataTable>
        </c:forEach>
    </ui:define>

    <ui:define name="popup">
        <t:panelGrid columns="3">

            <h:outputLabel for="inputInstructeur" value="Instructeur"/>
            <p:selectOneMenu value="#{gestSessionBean.session.instructeur}"
                             converter="#{genericConverter}" id="inputInstructeur"
                              >
                <f:selectItem itemDisabled="true" itemLabel="Choisir un instructeur ..." />
                <f:selectItems value="#{gestSessionBean.formation.listInstructeur}"
                               var="personne" itemLabel="#{personne.grade} #{personne.nom}" />
            </p:selectOneMenu>
            <p:message for="inputInstructeur"/>

            <h:outputLabel for="inputSalle" value="Salle"/>
            <p:selectOneMenu value="#{gestSessionBean.session.salle}"
                             converter="#{genericConverter}" id="inputSalle"
                              >
                <f:selectItem itemDisabled="true" itemLabel="Choisir une salle ..." />
                <f:selectItems value="#{gestSessionBean.listSalle}"
                               var="salle" itemLabel="#{salle.libPiece} (#{salle.nbPlace})"/>
                <p:ajax update="sliderMini, sliderMax"/>
            </p:selectOneMenu>
            <p:message for="inputSalle"/>

            <h:outputLabel for="inputNbMini" value="Nb Place Min"/>
            <t:panelGroup>
                <p:inputText id="inputNbMini" value="#{gestSessionBean.session.nbPlaceMini}"/>  
                <p:slider id="sliderMini" for="inputNbMini" minValue="1" maxValue="#{gestSessionBean.session.salle.nbPlace}"/>
            </t:panelGroup>
            <p:message for="inputNbMini"/>

            <h:outputLabel for="inputNbMax" value="Nb Place Max"/>
            <t:panelGroup>
                <p:inputText id="inputNbMax" value="#{gestSessionBean.session.nbPlaceMax}"/>
                <p:slider id="sliderMax" for="inputNbMax" minValue="1" maxValue="#{gestSessionBean.session.salle.nbPlace}"/>
            </t:panelGroup>
            <p:message for="inputNbMax"/>

            <t:panelGroup colspan="3">
                <p:scrollPanel style="width:350px;height:200px">
                    <p:dataTable value="#{gestSessionBean.session.listSeance}" var="seance">
                        <p:column headerText="Séances">
                    <h:outputLabel for="inputSeance" value="Début (#{seance.duree}H)"/>
                    <p:calendar id="inputSeance" pattern="dd/MM/yyyy HH:mm" 
                                mindate="#{gestSessionBean.formation.dateDebut}" maxdate="#{gestSessionBean.formation.dateFin}"
                                minHour="7" maxHour="#{17-seance.duree}" value="#{seance.dateHeureDebut}"
                                 />
                    <p:message for="inputSeance"/>
                    </p:column>
                </p:dataTable>
                </p:scrollPanel>
            </t:panelGroup>
        </t:panelGrid>
        
        <opif:validationButton managedBean="#{gestSessionBean}"
                               libelleValidation="Créer"
                               actionValidation="validerCreer"
                               onclick="popup.hide()"
                               update="dataTableListeSession messages"
                               rendered="#{gestSessionBean.modeCreation}"/>
        
        <opif:validationButton managedBean="#{gestSessionBean}"
                               libelleValidation="Modifier"
                               actionValidation="validerModifier"
                               onclick="popup.hide()"
                               update="dataTableListeSession messages"
                               rendered="#{!gestSessionBean.modeCreation}"/>
    </ui:define>
</ui:composition>
